package mp

import (
	"context"
	"errors"

	"ruikc.com/server/api/internal/db"
	"ruikc.com/server/api/internal/svc"
	"ruikc.com/server/api/internal/types"
	"ruikc.com/server/models"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type NewsInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNewsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewsInfoLogic {
	return &NewsInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NewsInfoLogic) NewsInfo(req *types.IdForm) (resp *types.NewsInfo, err error) {
	data := models.News{
		Id: req.Id,
	}
	has := db.GetData(&data)
	if !has {
		return nil, errors.New("数据不存在")
	}

	resp = &types.NewsInfo{}
	copier.Copy(resp, data)

	return resp, nil
}
